<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<div class="dialog-warp-ajax">
    <form action="" id="punishInforAdd">
        <table class="dggui-table-info">
            <input type="hidden" name="punishId" value="${punishId}">
            <tbody>
            <tr>
                <th><span class="required">业态：</span></th>
                <td>
                    <div>${ytName}</div>
                </td>
            </tr>
            <tr>
                <th><span class="required">团队：</span></th>
                <td id="teamHidden">
                    <input type="hidden" id="teamName" name="teamName">
                    <select id="cfTeam" name="teamId" class="dggui-select">
                        <option value="">请选择</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th><span class="required">操行分：</span></th>
                <td>
                    <input type="text" class="dggui-input" id="cfConductPoints" name="conductPoints">
                </td>
            </tr>
            <tr>
                <th><span class="required">金额：</span></th>
                <td>
                    <input type="text" class="dggui-input" id="cfMoney" name="money">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>
<script>
    dggui.use(['select2'], function (){
        var select2 = dggui.select2;
        //初始化团队
        initTeam("#cfTeam");
        select2.render({
            placeholder: "请选择",
            elem: $('#cfTeam'),
            allowClear: true,
            width: "280px"
        });
    })
    function punishInforCreate(index){
        var conductPoints = $('#cfConductPoints').val();
        var team = $('#cfTeam').val();
        var teamName = $('#cfTeam').find("option:selected").text();
        $("#teamName").val(teamName);
        var money = $('#cfMoney').val();
        var reg=/^(((\d|[1-9]\d)(\.\d{1,2})?)|100|100.0|100.00)$/;
        var regPoints = /^(0(\.\d{1,2})?|1(\.0{1,2})?)$/;


        if(team.trim()=='' || team.trim() == null){
            dggui.dialog.tip('请选择团队！',$('#teamHidden'));
            return;
        }
        if(conductPoints == ''){
            dggui.dialog.tip('数值不能为空！',$("#cfConductPoints"));
            return false;
        }
        if(!regPoints.test(conductPoints)){
            dggui.dialog.tip('操行分0-1之间，可保留小数点后两位！',$("#cfConductPoints"));
            return false;
        }
        if(money == ''){
            dggui.dialog.tip('数值不能为空！',$("#cfMoney"));
            return false;
        }
        if(!reg.test(money)){
            dggui.dialog.tip('金额0-100之间，可保留小数点后两位！',$("#cfMoney"));
            return false;
        }
        var params = $('#punishInforAdd').serializeArray();
        dggui.dialog.loading();
        $.ajax({
            type: 'POST',
            async: true,
            data: params,
            url: sysInfo.basePath + '/rzsc/punish/add_punish_infor.do',
            dataType: 'JSON',
            success: function (data) {
                dggui.dialog.loading('close');
                if (data.code == 0) {
                    layer.close(index);
                    dggui.dialog.succeed('操作成功！')
                    //刷新列表
                    searchPunish();
                    //window.location.reload();
                } else {
                    dggui.dialog.errors(data.msg);
                }
            },
            error: function () {
                dggui.dialog.loading('close');
                dggui.dialog.errors('保存失败，请联系管理员！！');
            }
        })
    }
</script>
